package com.zhidisoft.crm.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.zhidisoft.crm.entity.SysUser;


public class LoginInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		String root = request.getContextPath();//获取Tomcat的root的值
		String servletPath = request.getServletPath();//获取路径
		
		SysUser sysUser = (SysUser) request.getSession().getAttribute("user");
		if(StringUtils.isEmpty(sysUser)){
			response.sendRedirect(root+"/login?servletPath="+servletPath);
			return false;
		}
		return super.preHandle(request, response, handler);
	}
}
